//
//  UIbutton-Extension.swift
//  CMDB
//
//  Created by 曹桂祥 on 17/4/7.
//  Copyright © 2017年 CMDB. All rights reserved.
//

import UIKit

extension UIButton {
    
    convenience init(imageName:String,selectedImage : String) {
        
        self.init()
        
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: selectedImage), forState: .Selected)
        
        sizeToFit()
        
    }
    
    convenience init(bgColor : UIColor, fontSize : CGFloat, title : String) {
        self.init()
        
        setTitle(title, forState: .Normal)
        backgroundColor = bgColor
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
    }
    
    
    convenience init(title:String,imageName:String,selectedImage : String,isSizeToFit:Bool,color:UIColor,titleSizeFont : UIFont) {
        self.init()
        
        setTitle(title, forState: .Normal)

        titleLabel?.font = titleSizeFont
        
        titleEdgeInsets.left = 5
        
        setTitleColor(color, forState: .Normal)
        
        setImage(UIImage(named: imageName), forState: .Normal)
        
        setImage(UIImage(named: selectedImage), forState: .Selected)
        
        if isSizeToFit {
            sizeToFit()
        }
    }
    
    convenience init(title:String,borderColor : UIColor,titleSizeFont : UIFont,isShowBorder : Bool) {
        self.init()
        
        setTitle(title, forState: .Normal)
        
        titleLabel?.font    = titleSizeFont
        
        layer.cornerRadius  = 5
        
        layer.masksToBounds = true
        
        setTitleColor(word87Color, forState: .Normal)
        
        setTitleColor(borderColor, forState: .Selected)
        
        layer.borderColor   = borderColor.CGColor
        
        if isShowBorder {
            
            layer.borderWidth   = 0.5
            
        }
        
        sizeToFit()
    }
}

